import request from '@/utils/request'

// 获取数据字典
export function getDictByGroupName(groupName) {
  return request({
    url: '/common/getDictByGroupName',
    method: 'get',
    params: {
      groupName: groupName
    }
  })
}

// 查询多个数据数据字典
export function getDictByGroupNameList(data) {
  return request({
    url: '/common/getDictByGroupNameList',
    method: 'post',
    data
  })
}

// 获取公共据字典
export function getDictCommon() {
  return request({
    url: '/common/getDictCommon',
    method: 'get',
    params: {}
  })
}

// 获取物流列表
export function listExpress() {
  return request({
    url: '/common/listExpress',
    method: 'get'
  })
}
// 获取银行列表
export function listBank() {
  return request({
    url: '/common/listBank',
    method: 'get'
  })
}

// 获取物流轨迹
export function queryExpress(orderId) {
  return request({
    url: '/common/queryExpress',
    method: 'get',
    params: {
      orderId
    }
  })
}

// 获取物流轨迹
export function queryExpressByApartOrderId(apartOrderId) {
  return request({
    url: '/common/queryExpressByApartOrderId',
    method: 'get',
    params: {
      apartOrderId
    }
  })
}

// 获取七牛token
export function getQiniuToken() {
  return request({
    url: '/common/getQiniuToken',
    method: 'get'
  })
}
// 获取最新公告
export function getLastNotice(enterpriseId) {
  return request({
    url: '/common/getLastNotice',
    method: 'get',
    params: {
      enterpriseId
    }
  })
}

// 更新公告为已读
export function updateNoticeAsRead(enterpriseId, noticeId) {
  return request({
    url: '/common/updateNoticeAsRead',
    method: 'post',
    params: {
      enterpriseId,
      noticeId
    }
  })
}

// 下载文件
export function downloadFile(url, params, name) {
  request({
    url: url,
    method: 'get',
    params: params,
    responseType: 'blob'
  }).then(response => {
    const data = window.URL.createObjectURL(new Blob([response]))
    const aTag = document.createElement('a')
    const extIndex = url.lastIndexOf('.')
    aTag.download = name + (extIndex > 0 ? url.substring(extIndex) : '')
    aTag.href = data
    aTag.click()
  })
}
/**
 * 跳转到报表中心
 * @param {Object} that   调用者的当前对象，传 this
 * @param {Object} query  参数
 * @param {Object} isOpenNewWindow  是否打开新窗口,默认是：true
 */
export function jumpToReportCenter(that, query, isOpenNewWindow) {
  if (!isOpenNewWindow) {
    isOpenNewWindow = true
  }
  if (!query) {
    query = {}
  }
  if (isOpenNewWindow) {
    const routeData = that.$router.resolve({
      path: '/dataAnalysis/reportCenter/index',
      query: query
    })
    window.open(routeData.href, '_blank')
  } else {
    that.$router.push({
      path: '/dataAnalysis/reportCenter/index',
      query: query
    })
  }
}

export function refreshMemberWxaCode(enterpriseId, memberId) {
  return request({
    url: '/common/refreshMemberWxaCode',
    method: 'get',
    params: {
      memberId,
      enterpriseId
    }
  })
}
